package com.wanmait.community.controller;

import com.wanmait.community.entity.User;
import com.wanmait.community.service.UserService;
import com.wanmait.community.util.AjaxResult;
import com.wanmait.community.util.IPUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class CommonController {
    @Resource
    private UserService userService;
    @PostMapping("login")
    public AjaxResult login(HttpServletRequest request,@Validated @RequestBody User user) {
        System.out.println(user);
        String ip = IPUtils.getClientIpAddr(request);
        user.setLoginIp(ip);
        return userService.login(user);
    }
}
